package com.example.dbcenter.dbase;

import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.util.StringUtils;

import java.lang.annotation.Annotation;

public class DbHelper {
    private String chartset;

    public String convertChartsetSQL(String sql) {
        if (StringUtils.isEmpty(this.chartset)) {
            return sql;
        } else {
            try {
                return new String(sql.getBytes("GBK"), this.chartset);
            } catch (Exception var3) {
                return sql;
            }
        }
    }

    /**
     *
     * @param cl
     * @return String
     */
    public String fetchAnnotationTableName(Class<?> cl) {
        Annotation[] annos = cl.getAnnotations();
        Annotation[] var3 = annos;
        int var4 = annos.length;

        for(int var5 = 0; var5 < var4; ++var5) {
            Annotation ann = var3[var5];
            if (ann instanceof Document) {
                return ((Document)ann).collection();
            }
        }

        String name = cl.getName();
        name = name.substring(name.lastIndexOf(".") + 1).toLowerCase();
        return name.endsWith("bean") ? name.substring(0, name.length() - 4) : name;
    }
}
